package com.example.administrator.yaoyiyaotest01;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;


/**
 * Created by Administrator on 2016/6/22.
 */
public class MyView extends View {

    private String text;
    private Paint mPaint;
    private Canvas mcanvas;
    public MyView(Context context) {
        super(context);
        init();
        System.out.println("--->1");
    }
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        System.out.println("--->2");
    }
    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
        System.out.println("--->3");
    }
    private void init(){
        mPaint = new Paint();
        mPaint.setAntiAlias(true);          //抗锯齿
        mPaint.setColor(Color.YELLOW);//画笔颜色
        mPaint.setStyle(Paint.Style.FILL);  //画笔风格
        mPaint.setTextSize(36);             //绘制文字大小，单位px
        mPaint.setStrokeWidth(5);           //画笔粗细
    }
    //重写该方法，在这里绘图
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawColor(Color.BLUE);   //设置画布背景颜色
        canvas.drawText(""+text,100,100,mPaint);




    }

   public void setText(String text) {
       this.text = text;
       invalidate();
   }


}
